﻿@using XStudio.Framework.Support.Entity.Authorize
@using XStudio.WebFramework.Mvc.Extensions
@model XStudio.Framework.Support.Entity.User.EmployeeViewEntity
<script src="@Url.Content("~/Scripts/plugins/PasswordStrength/PasswordStrength.js")" type="text/javascript"></script>
<form name="frmInput" id="frmInput" method="post" action="@Url.Action(ViewContext.RouteData.Values["Action"].ToString())">
<div style="padding-left: 1.5em;">
    <table class="tbl-input" cellspacing="0">
        <colgroup>
            <col style="width: 150px;" />
            <col class="w4" />
            <col />
        </colgroup>
        <tbody>
            @*   <tr>
                <th scope="row">
                    <span class="btnTitleNormal btnUser" style="text-align: right; margin-right: -5px"><a
                        href="JavaScript:void(0);" onclick="JavaScript:SelectParentEmployee()">直属上级</a><span>：</span>
                    </span>
                </th>
                <td>
                    @Html.Hidden("ParentEmployeeID", ViewData["ParentEmployeeID"]); <tt id="txtParentEmployeeName"
                        style="font-size: 10.4pt"></tt>
                </td>
                <td class="slight">
                    <span class="btn-infomust">必填项，请选择直属上级。</span>
                </td>
            </tr>*@
            <tr>
                <th scope="row">
                    用户帐号：
                </th>
                <td>
                    @Html.TextBox("Account", ViewData["Account"], new { @Style = "width:200px", maxlength = "25" })
                </td>
                <td class="slight">
                    <span class="btn-infomust" style="text-align:left">必填项，请正确填写帐号。</span>
                </td>
            </tr>
            <tr>
                <th scope="row">
                    用户姓名：
                </th>
                <td>
                    @Html.TextBoxFor(t => t.EmployeeName, new { @Style = "width:200px", maxlength = "25" })
                </td>
                <td class="slight">
                    <span class="btn-infomust">必填项，请如实填写用户信息。</span>
                </td>
            </tr>
            <tr>
                <th scope="row">
                    所属区域：
                </th>
                <td>
                    @Html.InstitutionDropDownList("InstitutionID", 0, Model.InstitutionID.ToString(), "请选择区域", "-1", new { style = "width:200px" })
                </td>
                <td class="slight">
                    <span class="btn-infomust">必填项，请选择所属区域。</span>
                </td>
            </tr>
            @if (!string.Equals(ViewContext.RouteData.Values["Action"].ToString(), "Edit"))
            {
                <tr>
                    <th scope="row">
                        登录密码：
                    </th>
                    <td>
                        @Html.Password("Password", "", new { @Style = "width:200px", maxlength = "25" })
                    </td>
                    <td class="slight">
                        <span class="btn-infomust">必填项，请输入用户登录密码。</span>
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        确认密码：
                    </th>
                    <td>
                        @Html.Password("ConfirmPassword", "", new { @Style = "width:200px", maxlength = "25" })
                    </td>
                    <td class="slight">
                        <span class="btn-infomust">必填项，请输入确认密码。</span>
                    </td>
                </tr>
            }
            <tr>
                <th scope="row">
                    联系电话：
                </th>
                <td>
                    @Html.TextBoxFor(t => t.MobilePhone, new { @Style = "width:200px", maxlength = "25" })
                </td>
                <td class="slight">
                    <span class="btn-info">选填项。</span>
                </td>
            </tr>
            @{
                var roles = ViewBag.Roles as List<RoleEntity>;
            }
            @if (Html.Auth("SetAuthorize") && roles != null && roles.Count > 0)
            {
                var index = 0;

                foreach (var role in roles)
                {
                <tr>
                    @if (index == 0)
                    {
                        <th  rowspan="@roles.Count" style="vertical-align: top; padding-top: 10px;">
                            权限：
                        </th>
                    }
                    @if (index == 0)
                    {
                        <td>
                            <input type="checkbox" value="@role.UID" @(role.StateCodeID == 9 ? "checked='checked'" : "")    name="role" id="@string.Format("role_{0}", role.UID)" />
                            <label  for="@string.Format("role_{0}", role.UID)" >
                                @role.RoleName
                            </label>
                        </td>
                        <td style="display: none" id="HideRemark" class="slight">
                            <span class="btn-info">@role.Remark</span>
                        </td>
                    }
                    else
                    {
                        <td>
                            <input type="checkbox" value="@role.UID" @(role.StateCodeID == 9 ? "checked='checked'" : "")    name="role" id="@string.Format("role_{0}", role.UID)" />
                            <label  for="@string.Format("role_{0}", role.UID)" >
                                @role.RoleName
                            </label>
                        </td>
                        <td class="slight">
                            <span class="btn-info">@role.Remark</span>
                        </td>
                    }
                </tr>

                    index++;
                }
            }
            <tr>
                <th scope="row">
                    账号状态：
                </th>
                <td>
                    @Html.CheckBox("StateCodeID", Model.StateCodeID == 1, new { value = "1" })
                    <label for="StateCodeID">
                        是否启用</label>
                </td>
            </tr>
        </tbody>
    </table>
</div>
<div class="lineSolid" style="margin: 15px 10px 0 10px">
</div>
<div style="padding: 15px; text-align: center">
    <input type="button" value="保存" onclick="Input.Save(this)" class="btn-8" />
    <span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
    <input type="button" value="返回" onclick="Input.Back(this)" class="btn-8" />
</div>
<div id="summary" class="hidden" style="text-align: center">
    <span class="btn-infomust">表单有错误，请检查！</span>
</div>
</form>
@Html.Hidden("AreaUrl", Url.Action("GetArea"))
<script type="text/javascript">
    var Input = {};
    $(document).ready(function () {
        Common.BindWarp();
        $("#Password").pstrength();

        //表单验证
        var v = $("#frmInput").validate({
            focusInvalid: true,
            rules: {
                Account: { required: true },
                Password: { required: true },
                InstitutionID: { required: true, min: 0 },
                ConfirmPassword: { required: true, equalTo: "#Password" },
                EmployeeName: { required: true },
                Email: { email: true }
            },
            messages: {
                Account: { required: "请输入帐号！" },
                Password: { required: "请输入密码！" },
                InstitutionID: { required: "必填项！", min: "必填项！" },
                ConfirmPassword: { required: "请输入确认密码！", equalTo: "两次密码不一致！" },
                EmployeeName: { required: "请输入姓名！" },
                MobilePhone: { required: "请输入手机号码！" },
                Email: { required: "请输入邮箱！", email: "请输入正确的邮箱地址！" }
            },
            errorPlacement: function (error, element) {
                var objError = $(element.parents("td").next("td"));
                objError.removeClass("msg_infomust");
                objError.html(error);
            },
            success: function (element) {
                element.html("").addClass("tip-success");
            }
        });
    });

    Input.Save = function (e) {

        var frm = $(e).parents("form");
        if (!$(frm).valid())
            return false;

        $.ajax({
            url: $(frm).attr("action"),
            data: $(frm).serialize(),
            type: "Post",
            error: function (request) {
                alert('保存出错，请重试！');
            },
            success: function (data) {
                if (data.IsOK) {
                    //刷新列表
                    $('#tbList').datagrid('reload');

                    //关闭选项卡
                    Common.CloseTab();
                }
                else
                    alert(data.Description);
            }
        });
    }

    Input.Back = function () {
        Common.CloseTab();
    }

    function GetAreaCity() {
        $("#areaCity").empty();
        var url = $("#AreaUrl").val() + "/" + $("#areaProvince").val();
        $("#AreaCodeID").val($("#areaProvince").val());
        $.getJSON(url, function (data) {
            $.each(data, function (i, item) {
                $("<option></option>")
                .val(item["Value"])
                .text(item["Text"])
                .appendTo($("#areaCity"));
            });
        });
    }

    function SetAreaCity() {
        var areaCode = $("#areaCity").val();
        $("#areaCode").val("false");
        if (areaCode != -1) {
            $("#AreaCodeID").val($("#areaCity").val());
        } else {
            $("#AreaCodeID").val("0");
        }
    }
</script>
